(* MyHorner *)

Clear["`*"]

p1=1+2x+5x^2+4x^3+2x^4

p2=5+4x+2x^3+x^6

p3=1+2y+3y^2

p4=1+x+x y+(a+b)x^2-c x^2 +x^3

q=2/x^3

{p1/.x->1,p2/.x->1,p3/.x->1,p4/.x->1}

{p1/.x->2,p2/.x->2,p3/.x->2,p4/.x->2}

{PolynomialQ[p1,x],PolynomialQ[p2,x],PolynomialQ[p3,x],PolynomialQ[p4,x],PolynomialQ[q,x]}

PolEval1[pol_, x_  ,r_?NumberQ]/;PolynomialQ[pol,x]:=Module[{p,ln,v},
		p=Collect[Expand[pol],x];
		ln=Length[p];
		For[v=0;i=1, i<=ln, i++, v=v+p[[i]]/.x->r];v]

PolEval1[p4,x,2]

PolEval1[p1,x,2]

PolEval1[q,x,2]

MyMyHorner[c_List, x_]:=Fold[Function[{a,b}, a x + b], 0, c]

MyHornerfun[c_List, x_]:=Fold[#1 x + #2 &, 0, c]

MyHorner[{2,4,5,2,1},x]

MyHorner[{2,4,5,2,1},x]//Expand

MyHorner[{2,4,5,2,1},2]

{MyHorner[{2,4,5,2,1},6],BaseForm[3649,6]}

MyHorner[{1,1,1,1,1},2]

HornerForm[p1] (* συνάρτηση της Mathematica *)

IntegerDigits[31,2]

{BaseForm[31,2], 2^^11111}

MyHorner[{a,b,c,d},x]
Expand[%]

p2

Reverse[Prepend[Cases[p2,c_. x^n_.->c],Select[p2,FreeQ[#,x]&]]]

MyHorner[{1,2,4,5},2]

MyCFL[p_,x_]:=Module[{n,i},
		n=Exponent[p,x];
		Reverse[Prepend[Table[Coefficient[p,x^i],{i,1,n}],Select[p,FreeQ[#,x]&]]]]
MyCFL[p2,x]

Reverse[CoefficientList[p2,x]]

MyHorner[{1,0,0,2,0,4,5},2]

Clear[PolEval2];
PolEval2[pol_, x_  ,r_?NumberQ]/;PolynomialQ[pol,x]:=
Module[{p=Collect[Expand[pol],x]},
		MyHorner[Reverse[CoefficientList[p,x]],r]]

PolEval2[p2,x,2]

Clear[PolEval3];
PolEval3[pol_, x_  ,r_?NumberQ]/;PolynomialQ[pol,x]:=
Module[{p=Collect[Expand[pol],x]},
		MyHorner[MyCFL[p,x],r]]

PolEval3[p2,x,2]